Developer Documentation
PATH  Mac OS X Documentation > Developer Tools > The Objective-C Compiler


Previous | Contents | Next

Interoperation

This section lists various difficulties encountered in using GNU C or GNU C++ together with other compilers or with the assemblers, linkers, libraries and debuggers on certain systems.

GNU C++ does not do name mangling in the same way as other C++ compilers. This means that object files compiled with one compiler cannot be used with another.

This effect is intentional, to protect you from more subtle problems. Compilers differ as to many internal details of C++ implementation, including: how class instances are laid out, how multiple inheritance is implemented, and how virtual function calls are handled. If the name encoding were made the same, your programs would link against libraries provided from other compilers--but the programs would then crash when run. Incompatible libraries are then detected at link time, rather than at run time.

As a result, if a function compiled with Sun CC takes the address of an argument of type double and passes this pointer of type double * to a function compiled with GNU CC, dereferencing the pointer may cause a fatal signal.

One way to solve this problem is to compile your entire program with GNU CC. Another solution is to modify the function that is compiled with Sun CC to copy the argument into a local variable; local variables are always properly aligned. A third solution is to modify the function that uses the pointer to dereference it via the following function access_double instead of directly with * :

inline double access_double (double *unaligned_ptr) { union d2i { double d; int i[2]; }; union d2i *p = (union d2i *) unaligned_ptr; union d2i u; u.i[0] = p->i[0]; u.i[1] = p->i[1]; return u.d; }

Storing into the pointer can be done likewise with the same union.

The solution is to not use the libmalloc.a library. Use instead malloc and related functions from libc.a ; they do not have this problem.

(warning) Use of GR3 when frame >= 8192 may cause conflict.

These warnings are harmless and can be safely ignored.


The Objective-C Compiler

Previous | Contents | Next